package com.lancoo.answer.util;

import android.content.Context;
import android.content.res.AssetManager;
import com.google.gson.Gson;
import com.lancoo.answer.model.bean.CognitiveBean;
import com.lancoo.answer.model.bean.ExamViewBean;
import com.lancoo.answer.model.bean.XgPaResultBean;
import com.lancoo.answer.model.bean.XgSaBean;
import com.lancoo.answer.model.bean.XgSaBeanItem;
import com.lancoo.answer.model.bean.XgSaBigReviewBean;
import com.lancoo.answer.model.bean.XgSaCognitiveBean;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

/**
 * Created by Dadong on 2021/12/8
 * Describe:
 */
public class GetJsonDataUtil {
    public static ExamViewBean getJson(Context context) {
        StringBuilder stringBuilder = new StringBuilder();
        try {
            AssetManager assetManager = context.getAssets();
            BufferedReader bf = new BufferedReader(new InputStreamReader(assetManager.open("TestData.Json")));
            String line;
            while ((line = bf.readLine()) != null) {
                stringBuilder.append(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        stringBuilder.toString();
        return new Gson().fromJson(stringBuilder.toString(), ExamViewBean.class);
    }

    public static CognitiveBean getCognitiveBeanJson(Context context) {
        StringBuilder stringBuilder = new StringBuilder();
        try {
            AssetManager assetManager = context.getAssets();
            BufferedReader bf = new BufferedReader(new InputStreamReader(assetManager.open("ResultData.json")));
            String line;
            while ((line = bf.readLine()) != null) {
                stringBuilder.append(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        stringBuilder.toString();
        return new Gson().fromJson(stringBuilder.toString(), CognitiveBean.class);
    }

    /*
    * todo 获取试卷作答结果详情
    * */
    public static XgPaResultBean getXgResultDataJson(Context context) {
        StringBuilder stringBuilder = new StringBuilder();
        try {
            AssetManager assetManager = context.getAssets();
            BufferedReader bf = new BufferedReader(new InputStreamReader(assetManager.open("XgResultData.json")));
            String line;
            while ((line = bf.readLine()) != null) {
                stringBuilder.append(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        stringBuilder.toString();
        return new Gson().fromJson(stringBuilder.toString(), XgPaResultBean.class);
    }

    /*
     * todo 获取同类题试题模型
     * */
    public static XgSaBean getXgSaBeanDataJson(Context context) {
        StringBuilder stringBuilder = new StringBuilder();
        try {
            AssetManager assetManager = context.getAssets();
            BufferedReader bf = new BufferedReader(new InputStreamReader(assetManager.open("XgSaData.json")));
            String line;
            while ((line = bf.readLine()) != null) {
                stringBuilder.append(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        stringBuilder.toString();
        return new Gson().fromJson(stringBuilder.toString(), XgSaBean.class);
    }


    /*
     * todo 获取同类题作答结果详情
     * */
    public static XgSaBigReviewBean getXgSaBigReviewDataJson(Context context) {
        StringBuilder stringBuilder = new StringBuilder();
        try {
            AssetManager assetManager = context.getAssets();
            BufferedReader bf = new BufferedReader(new InputStreamReader(assetManager.open("XgSaBigReviewData.json")));
            String line;
            while ((line = bf.readLine()) != null) {
                stringBuilder.append(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        stringBuilder.toString();
        return new Gson().fromJson(stringBuilder.toString(), XgSaBigReviewBean.class);
    }

    /*
     * todo 获取同类题认知及预估成绩
     * */
    public static XgSaCognitiveBean getXgSaCognitiveDataJson(Context context) {
        StringBuilder stringBuilder = new StringBuilder();
        try {
            AssetManager assetManager = context.getAssets();
            BufferedReader bf = new BufferedReader(new InputStreamReader(assetManager.open("XgSaCognitiveData.json")));
            String line;
            while ((line = bf.readLine()) != null) {
                stringBuilder.append(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        stringBuilder.toString();
        return new Gson().fromJson(stringBuilder.toString(), XgSaCognitiveBean.class);
    }

}
